package controller.api;
import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.kit.Kv;
import com.jfinal.kit.Ret;

import common.inter.ServicerStationInter;
import common.inter.StaffStationInter;
import enums.MaintainRecordsType;
import model.MaintainRecords;
import service.MaintainRecordsService;

public class ApiMaintainRecordsController extends BaseApiController {
	@Inject MaintainRecordsService maintainRecordsService ;

	@Before(ServicerStationInter.class)
	public void list() {
	    Kv kv = getParamKv() ;
	    kv.set("tmr.stationId", getStation().getId());
	    Integer pageNumber = getParaToInt("pageNumber", 1);
	    Integer pageSize = getParaToInt("pageSize", 10);
	    set("page", maintainRecordsService.getApiPage( kv , pageNumber, pageSize));
	    set("maintainRecordsTypeList", MaintainRecordsType.toList());
	    renderJson();
	}
	
	public void typeList() {
		renderJson("list" , MaintainRecordsType.toList());
	}

	@Before(StaffStationInter.class)
	public void save() {
		MaintainRecords maintainRecords = getModel(MaintainRecords.class , "x");
        Ret ret = maintainRecordsService.save(maintainRecords , getStation() , getStaff() );
        renderJson(ret);
	}
	
	@Before(ServicerStationInter.class)
	public void recentRecords() {
		renderJson( maintainRecordsService.recentRecords(getStation()) );
	}
}
